package com.jlsoft.web.cmn.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.jlsoft.config.SimpleResponse;
import com.jlsoft.entity.Permission;
import com.jlsoft.service.IPermissionService;
import com.jlsoft.web.cmn.service.IMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class MenuServiceImpl implements IMenuService {
    @Override
    public List<Permission> getMenuList() {
          List<Permission> result =permissionService.selectList(new EntityWrapper<Permission>()
            .orderBy("id").orderBy("parent_id").orderBy("order_id")
        );

        result.stream().forEach((permission -> {
            permission.setUrl("/index"+permission.getUrl());
        })) ;

        return  result;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public SimpleResponse updatePermisson(Permission permission) {

        if(permissionService.updateById(permission))
            return new SimpleResponse(0, "修改成功", true);
        else
            return new SimpleResponse(1, "修改失败", false);

    }

    @Autowired
    private IPermissionService permissionService;
}
